<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
import echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import resize from './mixins/resize'

const animationDuration = 3000

export default {
  mixins: [resize],
  props: {
    data:{

    },
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '500px'
    }
  },
  data() {
    return {
      chart: null
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart()
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')

      this.chart.setOption({
          tooltip: {
            trigger: 'item'
          },
          legend: {
            orient: 'vertical',
            left: 'left'
          },
          series: [
            {
              name: '数据详情',
              type: 'pie',
              radius: '50%',
              data: [
                {
                  value: this.data.tp,
                  name: '投票所得',
                  itemStyle: {
                  normal: {
                      color: '#fc2b07',
                    },
                  }
                },
                {
                  value: this.data.sl,
                  name: '刷礼物所得',
                  itemStyle: {
                  normal: {
                      color: '#ffe910',
                    },
                  }
                },
                {
                  value: this.data.ht,
                  name: '后台赠送',
                  itemStyle: {
                  normal: {
                      color: '#909399',
                    },
                  }
                },

              ],
              emphasis: {
                itemStyle: {
                  shadowBlur: 10,
                  shadowOffsetX: 0,
                  shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
              }
            }
          ]

      })
    }
  }
}
</script>
